home *** CD-ROM | disk | FTP | other *** search
- /*
- TestFunctions.c
-
- Functions for the Test menu commands.
-
- © 1995 Apple Computer, Inc.
- */
- #include <Types.h>
- #include <QuickDraw.h>
- #include <Dialogs.h>
- #include <Memory.h>
- #include <Windows.h>
-
- #include <Files.h>
- #include <TextUtils.h>
- #include <ColorPicker.h>
-
- #include "EventLoop.h"
- #include "MenuDispatch.h"
- #include "QD3DViewer.h"
-
- PicHandle gPicture;
- extern WindowPtr MainView;
-
- void ChooseTest(short item);
- pascal void DrawPictureItem(WindowPtr theWindow, short itemNo);
- void DoInfoDialog(Str255 str1, Str255 str2, Str255 str3, Str255 str4, Str255 strPrompt);
- void DoBoundsInfoDialog(Rect *bounds, Str255 strPrompt);
-
- enum
- {
- tcItemOK = 1,
- tcItemText1,
- tcItemText2,
- tcItemPict
- };
-
- void ChooseTest(short item)
- {
- short iType, itemHit;
- Handle iHandle;
- Rect iRect;
- DialogPtr testDialog;
- OSErr anErr = noErr;
- unsigned long width, height;
- Str255 widthStr, heightStr;
- Rect bounds;
- TVCDemoDataHdl demoData;
- TQ3ViewerObject aViewer;
-
- if (FrontWindow() != MainView)
- goto ExitChooseTest;
- demoData = (TVCDemoDataHdl)GetWRefCon(MainView);
- aViewer = (*demoData)->viewer1;
- switch(item)
- {
- case cmdGetPicture:
- {
- PicHandle aPicture;
- UserItemUPP userItemUPP;
-
- aPicture = Q3ViewerGetPict(aViewer); /* get a picture of the view */
- if (aPicture)
- {
- gPicture = aPicture;
-
- // Display the picture
- testDialog = GetNewDialog(GETINFO_ID, nil, (WindowPtr)-1);
- ParamText("\p", "\p", "\p", "\p");
- GetDialogItem(testDialog, tcItemText1, &iType, &iHandle, &iRect);
- SetDialogItemText(iHandle, "\pGet Picture");
- GetDialogItem(testDialog, tcItemPict, &iType, &iHandle, &iRect);
- userItemUPP = NewUserItemProc(DrawPictureItem);
- SetDialogItem(testDialog, tcItemPict, iType, (Handle)userItemUPP, &iRect);
- ShowWindow(testDialog);
- do
- {
- ModalDialog(nil, &itemHit);
- } while (itemHit != tcItemOK);
- DisposeDialog(testDialog);
- DisposeRoutineDescriptor(userItemUPP);
- KillPicture(aPicture);
- gPicture = nil;
- }
- break;
- }
-
- case cmdGetDimensions:
- {
- anErr = Q3ViewerGetDimension(aViewer, &width, &height);
-
- NumToString(width, widthStr);
- NumToString(height, heightStr);
-
- DoInfoDialog(widthStr, heightStr, "\p", "\p", "\pGet Dimensions (width, height)");
- break;
- }
-
- case cmdGetCameraRect:
- {
- anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonCamera, &bounds);
- DoBoundsInfoDialog(&bounds, "\pGet Camera Button Rect (top, left, bottom, right)");
- break;
- }
- case cmdGetTruckRect:
- {
- anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonTruck, &bounds);
- DoBoundsInfoDialog(&bounds, "\pGet Truck Button Rect (top, left, bottom, right)");
- break;
- }
- case cmdGetOrbitRect:
- {
- anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonOrbit, &bounds);
- DoBoundsInfoDialog(&bounds, "\pGet Orbit Button Rect (top, left, bottom, right)");
- break;
- }
- case cmdGetZoomRect:
- {
- anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonZoom, &bounds);
- DoBoundsInfoDialog(&bounds, "\pGet Zoom Button Rect (top, left, bottom, right)");
- break;
- }
- case cmdGetDollyRect:
- {
- anErr = Q3ViewerGetButtonRect(aViewer, kQ3ViewerButtonDolly, &bounds);
- DoBoundsInfoDialog(&bounds, "\pGet Dolly Button Rect (top, left, bottom, right)");
- break;
- }
-
- case cmdGetBounds:
- {
- anErr = Q3ViewerGetBounds(aViewer, &bounds);
- DoBoundsInfoDialog(&bounds, "\pGet Bounds (top, left, bottom, right)");
- break;
- }
-
- case cmdSetBounds:
- break;
-
- case cmdGetBackgroundColor:
- break;
-
- case cmdSetBackgroundColor:
- {
- Point where = {-1, -1};
- RGBColor oldBColor, newBColor;
- TQ3ColorARGB qOldBColor, qNewBColor;
-
- Q3ViewerGetBackgroundColor(aViewer, &qOldBColor);
- oldBColor.red = qOldBColor.r * 65535.0;
- oldBColor.green = qOldBColor.g * 65535.0;
- oldBColor.blue = qOldBColor.b * 65535.0;
- if (GetColor(where, "\pPick a background color:", &oldBColor, &newBColor))
- {
- qNewBColor.a = 1;
- qNewBColor.r = newBColor.red / 65535.0;
- qNewBColor.g = newBColor.green / 65535.0;
- qNewBColor.b = newBColor.blue / 65535.0;
- Q3ViewerSetBackgroundColor(aViewer, &qNewBColor);
- }
- break;
- }
-
- case cmdUseBoxData:
- case cmdUseGroupData:
- case cmdVerifyGroupData:
- case cmdResetPort:
- break;
- case cmdWriteHandle:
- {
- Handle data;
- unsigned long size;
-
- size = Q3ViewerWriteData (aViewer, (void **)&data);
- size = GetHandleSize(data);
- size = size+1;
- break;
- }
- case cmdNormalMemory:
- case cmdPig500:
- case cmdPig100:
- break;
- default: break;
- }
- ExitChooseTest:
- ;
- }
-
-
- pascal void DrawPictureItem(WindowPtr theWindow, short itemNo)
- {
- short iType;
- Handle iHandle;
- Rect iRect, picRect;
-
- GetDialogItem(theWindow, itemNo, &iType, &iHandle, &iRect);
- picRect = (*gPicture)->picFrame;
- OffsetRect(&picRect, -picRect.left, -picRect.top);
- OffsetRect(&picRect, iRect.left, iRect.top);
- DrawPicture(gPicture, &picRect);
- }
-
- void DoInfoDialog(Str255 str1, Str255 str2, Str255 str3, Str255 str4, Str255 strPrompt)
- {
- short iType, itemHit;
- Handle iHandle;
- Rect iRect;
- DialogPtr testDialog;
- OSErr anErr = noErr;
-
- testDialog = GetNewDialog(GETINFO_ID, nil, (WindowPtr)-1);
- ParamText(str1, str2, str3, str4);
- GetDialogItem(testDialog, tcItemText1, &iType, &iHandle, &iRect);
- SetDialogItemText(iHandle, strPrompt);
- ShowWindow(testDialog);
- do
- ModalDialog(nil, &itemHit);
- while (itemHit != tcItemOK);
- DisposeDialog(testDialog);
- }
-
- void DoBoundsInfoDialog(Rect *bounds, Str255 strPrompt)
- {
- Str255 topStr, leftStr, rightStr, bottomStr;
-
- NumToString(bounds->top, topStr);
- NumToString(bounds->left, leftStr);
- NumToString(bounds->bottom, bottomStr);
- NumToString(bounds->right, rightStr);
-
- DoInfoDialog(topStr, leftStr, bottomStr, rightStr, strPrompt);
- }
-
- /* EOF */
-